package com.example.controller;

import com.example.common.ApiResult;
import com.example.service.OnlineUserTrackerService;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
public class AnalysisController {

    @Autowired
    private ObjectProvider<OnlineUserTrackerService> OnlineUserTrackerServiceProvider;

    @GetMapping("/analysis")
    public ApiResult<Long> onlineCount() {
        OnlineUserTrackerService tracker = OnlineUserTrackerServiceProvider.getIfAvailable();
        long count = tracker != null ? tracker.getOnlineCount() : 0L;
        return ApiResult.success("在线人数统计", count);
    }
}


